package com.afs.electronicforensics.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import com.afs.electronicforensics.adapter.TabFragmentAdapter;
import com.afs.electronicforensics.activity.R;
import com.google.android.material.tabs.TabLayout;

import java.util.ArrayList;
import java.util.List;

public class RecordFragment extends Fragment {
    private View viewContent;
    TabLayout my_tableLayout;
    ViewPager my_viewpager;


    private int mode = TabLayout.MODE_FIXED;

    public RecordFragment(){

    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        viewContent = (ViewGroup) inflater.inflate(R.layout.recyclerview_fragment, container, false);
        initContentView(viewContent);
        initData();

        return viewContent;
    }

    public void initContentView(View viewContent) {
        my_tableLayout = (TabLayout) viewContent.findViewById(R.id.tab_layout);
        my_viewpager = (ViewPager) viewContent.findViewById(R.id.viewpager);
    }

    public void initData() {
        TabFragmentAdapter adapter = new TabFragmentAdapter(getFragmentManager());
        List<Fragment> fragments = new ArrayList<Fragment>();
        fragments.add(new RecordLocalFragment());
        fragments.add(new RecordCloudFragment());
        String[] titlesArr = {"本机", "云端"};
        adapter.setTitlesArr(titlesArr);
        adapter.setFragments(fragments);
        this.my_viewpager.setAdapter(adapter);
        this.my_tableLayout.setupWithViewPager(this.my_viewpager);
        my_tableLayout.setTabMode(mode);
    }
}
